package task2_2;

import task2_2.com.at.count.Counter;
import task2_2.com.at.count.polsk.CounterException;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Task2Main {

    public static void main(String[] args) throws CounterException {

        Counter counter = new Counter();

//        counter.setExpression("144.5-308");
//        counter.setExpression("(4*(12 - 5)/2)*(12 + (41 - 11)/3)");  // - 308
//        counter.setExpression("(4*(12 - 5)/2)");  // - 14
//        counter.setExpression("(12 + (41 - 11)/3)");  // - 22
//        counter.setExpression("3 * (23*2 - 6/3)"); // - 123
//        counter.setExpression("10 + 3 * (23*2 - 6/3) + 5/2 - (12 + (41 - 11)/3)*(4*(12 - 5)/2)");

//        counter.setExpression("8.5*sin(5/5) - 5/sin(0-5)");

//        counter.setExpression("tan(" +Math.PI +"/4)");


        String expr = "(1710.355 - abs((2671.346) + (cos(4635.059))) * 4421.248 - ((5498.315)) - 2860.235 - (1742.560) / ((tan(9929.086)) * cos(2352.962) - ((tan((((962.692) * 4634.446 / 2865.958 / (6910.839)))) * tan(8257.578 - 2665.283 * (tan(3548.295)) * ((((tan(3219.630) - 4227.634))))) + cos(1944.008 / 7456.594) / cos(7824.618) * 7549.857) - tan(((8317.860)))) + 2728.764 - 3117.465 / 6089.095 * 447.604) + 8720.980)";
        counter.setExpression(expr);

        System.out.println(counter.count().setScale(32, RoundingMode.HALF_UP));

        double res = (1710.355 - abs((2671.346) + (cos(4635.059))) * 4421.248 - ((5498.315)) - 2860.235 - (1742.560) / ((tan(9929.086)) * cos(2352.962) - ((tan((((962.692) * 4634.446 / 2865.958 / (6910.839)))) * tan(8257.578 - 2665.283 * (tan(3548.295)) * ((((tan(3219.630) - 4227.634))))) + cos(1944.008 / 7456.594) / cos(7824.618) * 7549.857) - tan(((8317.860)))) + 2728.764 - 3117.465 / 6089.095 * 447.604) + 8720.980);
        System.out.println(new BigDecimal(res).setScale(6, RoundingMode.HALF_UP));
    }

    private static double abs(double val) {
        return Math.abs(val);
    }

    private static double sin(double val) {
        return Math.sin(val);
    }

    private static double cos(double val) {
        return Math.cos(val);
    }

    private static double tan(double val) {
        return Math.tan(val);
    }

}
